package group;

import java.util.*;

import javax.media.j3d.*;

import node.GeoNode;

public class GeoGroup extends BranchGroup {
	
	public GeoGroup() {
		super();
		
		this.setCapability(Group.ALLOW_CHILDREN_READ);
		this.setCapability(Group.ALLOW_CHILDREN_WRITE);
		this.setCapability(Group.ALLOW_CHILDREN_EXTEND);
	}
	
	public Collection<GeoNode> getGeoNodes() {
		Set<GeoNode> children = new HashSet<GeoNode>();
		@SuppressWarnings("rawtypes")
		Enumeration e = this.getAllChildren();
		while (e.hasMoreElements()) {
			Object o = e.nextElement();
			if (o instanceof GeoNode) {
				children.add((GeoNode)o);
			}
		}
		return Collections.unmodifiableSet(children);
	}
	
	public boolean contains(GeoNode node) {
		return getGeoNodes().contains(node);
	}
	
	public boolean intersect(GeoNode node) {
		Iterator<GeoNode> nodeIth = getGeoNodes().iterator();
		
		while (nodeIth.hasNext()) {
			if (nodeIth.next().intersect(node))
				return true;
		}
		return false;
	}

}
